app.controller('BindDemoCtrl',[
    '$scope','$state',
    function ($scope,$state) {
        $scope.text='des';
        
        $scope.ints=[{id:0,text:'启用'},{id:1,text:'停用'}];
        
        $scope.enumVals=['启用','停用'];
        
        $scope.selectedText=3;
        
        $scope.enumId=1;
        
        $scope.e= angular.extend({dd:1},$scope.enumVals);
        
        $scope.ok=function(){
          alert($scope.selectedText);  
        };
        
        $scope.go=function(state){
            $state.go(state,{p1:2342,p2:111});
        };
        
    } 
]);


app.controller('BindDemo1Ctrl',[
    '$scope','$state','$stateParams','bindDemoService',
    function ($scope,$state,$stateParams,bindDemoService) {
        $scope.demoText=$stateParams;
        
      bindDemoService.get()
        .then(function(result){           
            $scope.data=result;
        },function(x){
            alert(x);
        });
    } 
]);


    
app.factory('bindDemoService',[
    '$http','$q',
    function($http,$q){
        var self={};
        
        self.get=function(){
          var defer=$q.defer();
          
          $http({
              method:'GET',
              url:'tpl/demo/data.json'
          })
            .success(function(result){
                if(result.code>=0){
                    defer.resolve(result.data);
                }else{
                    defer.reject(result.message);
                }
            })
            .error(function (x) {
                console.error(x);
                defer.reject('请求数据失败');
            });
            return defer.promise;
        };
        
        return self;   
    }
]);
    
app.filter('enum',function(){
   return function(data,vals){
       return vals[data];
   } 
});
